package com.linux.huhx.thread3.reentrantreadwrite_1;

/**
 * @Author: huhx
 * @Date: 2017-10-31 上午 10:24
 */
public class Run {
    public static void main(String[] args) throws InterruptedException {
        Service service = new Service();
        Thread threadA = new ThreadA(service);
        threadA.setName("A");
        threadA.start();
        Thread.sleep(1000);

        Thread threadB = new ThreadB(service);
        threadB.setName("B");
        threadB.start();
    }
}

class ThreadA extends Thread {
    private Service service;

    public ThreadA(Service service) {
        super();
        this.service = service;
    }

    @Override
    public void run() {
        service.read();
    }
}

class ThreadB extends Thread {
    private Service service;

    public ThreadB(Service service) {
        super();
        this.service = service;
    }

    @Override
    public void run() {
        service.write();
    }
}